package com.suixingfu.utils;

import org.apache.commons.lang.StringUtils;

import com.suixingfu.vo.RequestMessage;

public class Decrypt {
    //解密
	public static void main(String[] args) throws Exception {
		
		String json="";//随行付返回的json数据
		
		RequestMessage requestMessage = JsonUtils.fromJson(json,RequestMessage.class);

		String sign = requestMessage.getSign();
		String resData = requestMessage.getResData();

		// 验证签名，随行付公钥
		String publicKey = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCDBJueJs8wh//LEvrMDKpb5Dcxaa8e3C9YtLzX8rxigm5cENlFlHMQRZtYfM900AhpH+1gsNz9/0zVCODrTjUyU+zSqqGvkY6igOhgX2UrTdByF7mIXeCWsrrRIirjsOUzmzR5AGMe8bk8AS5inzZYDaLWLulwwJDar2dy9gWgQwIDAQAB";
		
		boolean signFlag = sign !=null && StringUtils.isNotBlank(resData) && RSAUtils.verify(resData, sign, publicKey);
		if (!signFlag)
			System.out.println("签名验证失败");//根据实际业务修改

		// 解密
		byte[] base64bs = Base64Utils.decode(resData);
		
		// DES解密
		byte[] debs = DESUtils.decrypt(base64bs, "12345678");
		
		String resDataDecrypt = new String(debs,"UTF-8");
		
		requestMessage.setResData(resDataDecrypt);
		
		System.out.println(JsonUtils.toJson(requestMessage));

	}

}
